<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>plus会员套餐管理</title>
    <script src="../commonCss.js"></script>
    <script src="../commonJs.js"></script>
    <link rel="stylesheet" href="../../css/common.css">
</head>

<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <div class="ctc_title">plus会员套餐管理</div>
    <div class="down_line"></div>
</section>

<!-- Main content -->
<section class="content" >
    <div class="row">
        <div class="col-xs-12">
            <div class="box-header">
                <form class="form-inline">
                    <div class="form-group">
                        <label>查询：</label>
                        <input style="width: 200px;" class="form-control" type="text" id="searchKey"  placeholder="输入商品名称搜索"/>
                    </div>
                    <div class="form-group">
                        <button type="button"  onclick="getData()"  class="btn btn-block btn-primary">搜索</button>
                    </div>
                    <div style="float: right ">
                        <div class="form-group" style="margin-right: 20px;">
                            <button type="button" onclick="addInfo()" class="btn btn-block btn-primary">新增</button>
                        </div>
                    </div>

                </form>
            </div>

            <div class="box-body" style="height:100%;">
                <table id="dataList" class="table table-bordered table-hover">
                    <thead>
                        <tr>
                            <th>会员套餐名</th>
                            <th>价格（元）</th>
                            <th>有效期天数</th>
                            <th>排序</th>
                            <th>IOS内购ID</th>
                            <th>是否默认选中</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody >
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</section>

<!-- 【编辑】弹出窗内容 -->
<div class="modal" id="editPanel" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog" style="width: 50%;height: 40%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">×</span>
                    <span class="sr-only">Close</span>
                </button>
                <h4 class="modal-title" align="center" id="mopTitle"></h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" onsubmit="return false" id="form">
                    <fieldset  style="margin-top:2%;">
                        <input type="hidden" id="id" name="id">
                        <div class="form-group" >
                            <label class="col-md-2 control-label" style="color: red">*会员套餐名</label>
                            <div class="col-md-10">
                                <input class="form-control" placeholder="必填项" type="text"  id="goodsName" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label"  style="color: red">*价格（元）</label>
                            <div class="col-md-10">
                                <input class="form-control" placeholder="必填项" type="number"  id="price" min="0">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label"  style="color: red">*有效期天数</label>
                            <div class="col-md-10">
                                <input class="form-control" placeholder="必填项" type="number" id="days" min="0" >
                            </div>
                        </div>
                        <div class="form-group" >
                            <label class="col-md-2 control-label" >是否默认选中</label>
                            <div class="col-md-10">
                                <select id="default" class="form-control" style="text-align: center;font-size: 12px ;width:110px;">
                                    <option value="0">否</option>
                                    <option value="1">是</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label" >排序</label>
                            <div class="col-md-10">
                                <input class="form-control" type="number" name="sort" id="sort">
                            </div>
                        </div>
                    </fieldset>
                </form>
            </div>
            <div class="modal-footer" style="text-align: center">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="confirmEditConfig();">确定</button>
            </div>
        </div>
    </div>
</div>

<!-- 【图片点击放大】弹出窗内容 -->
<div class="modal" id="picMonthDialog" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true" >
    <div class="modal-dialog">
        <div class="modal-content">
            <img id="maxPic" height="50%" width="100%">
        </div>
    </div>
</div>
<!-- page script -->
<script>
    $(document).ready(function() {
        //加载数据
        getData();

    });

    // 加载数据
    function getData(){
        var table = $('#dataList').DataTable({
            "destroy": true,   //可以重新初始化，用于搜索
            "lengthChange": false,
            "ordering": false,   //排序
            "info": true,		   //
            "autoWidth": false,   //宽度自动
            "paging": true,      //分页
            "searching": false,  //全局搜索关闭
            "processing": true,  //开启显示‘正在加载.../processing’
            "serverSide":true,    //true代表后台处理分页，false代表前台处理分页
            "bPaginate": false, //开关，是否显示分页器
            "bLengthChange": false, //开关，是否显示每页显示多少条数据的下拉框
            "ajax" :  {
                url:"/plus/getPlusGoodsList",
                type:"POST",
                data:{
                     key : $("#searchKey").val()
                },
                dataSrc: function (myJson) {
                    return myJson.data.data;
                }
            },
            //参数显示
            "columns": [
                {"data": "name", 'sClass': "text-center",'width': '8%'},
                {"data": "price", 'sClass': "text-center",'width': '5%'},
                {"data": "days", 'sClass': "text-center",'width': '5%'},
                {"data": "sort", 'sClass': "text-center",'width': '5%'},
                {"data": "iosId", 'sClass': "text-center",'width': '6%'},
                {"data": "default", 'sClass': "text-center",'width': '3%',
                    "render":function( data, type, full, meta) {
                        var str="";
                        if(data == 0){
                            str += "<span class='label label-danger' style='padding-left:10px;padding-right:10px;padding-top: inherit;'>否</span>";
                        }else{
                            str += "<span class='label label-success' style='padding-left:10px;padding-right:10px;padding-top: inherit;' >是</span> ";
                        }
                        return str;
                    }
                },
                {"data": "id" , 'sClass': "text-center" ,'width':'4%',
                    "render": function (data, type, full, meta ) {
                        var str = '<a href = "#" title="编辑" onclick="editData(' + data + ", '" + full.name + "', '" + full.price + "', '" + full.days + "', '" + full.sort + "', '" + full.default + "'" + ');"><i class="glyphicon glyphicon-pencil"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                        str += '<a href = "#" title="删除" onclick="deleteData(' + data + ');"><i class="glyphicon glyphicon-trash"></i></a>';
                        return str;
                    }
                }
            ],

            //是否开启主题
            "bJQueryUI": true,
            "oLanguage": {    // 语言设置
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "sZeroRecords": "没有检索到数据",
                "sSearch": "检索:",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                }
            }
        });
    }

    //编辑
    function editData(id,goodsName,price,days,sort,defaul) {
        $("#id").val(id);
        $("#goodsName").val(goodsName);
        $("#price").val(price);
        $("#days").val(days);
        $("#sort").val(sort);
        $("#default").val(defaul);
        $("#mopTitle").text("编辑plus会员套餐");
        $("#editPanel").modal("show");//弹窗打开
    }

    //新增
    function addInfo() {
        $("#id").val("");
        $("#goodsName").val("");
        $("#price").val("");
        $("#days").val("");
        $("#sort").val("100");
        $("#default").val(0);
        $("#mopTitle").text("新增plus会员套餐");
        $("#editPanel").modal("show");//弹窗打开
    }


    //保存
    function confirmEditConfig(){
        var id = $("#id").val();
        var goodsName = $("#goodsName").val();
        var price = $("#price").val();
        var days = $("#days").val();
        var sort = $("#sort").val();
        var defaul = $("#default").val();

        if(goodsName == ""){
            layer.msg("会员套餐名称不能为空！");
            return ;
        }
        if(price == ""){
            layer.msg("价格不能为空！");
            return ;
        }else if(price <= 0){
            layer.msg("价格必须大于0！");
            return ;
        }

        if(days == ""){
            layer.msg("有效期天数不能为空！");
            return ;
        }else if(days <= 0){
            layer.msg("有效期天数必须大于0！");
            return ;
        }

        if(sort == ""){
            layer.msg("排序不能为空！");
            return ;
        }

        $.ajax({
            type:"POST",
            url:"/plus/updPlusGoods",
            async : true,//默认就是true
            dataType:"json",
            data:{
                id : id,
                name : goodsName,
                price :price,
                days: days,
                sort : sort,
                default :defaul
            },
            success : function(data) {
                layer.msg(data.message);
                $("#editPanel").modal("hide");
                getData();
            }
        });
    }

    //删除
    function deleteData(id) {
        if(confirm("确定要删除吗？")){
            $.ajax({
                type:"POST",
                url:"/plus/delPlusGoods",
                async : true,//默认就是true
                dataType:"json",
                data:{id : id},
                success : function(data) {
                    if(!data.error){
                        layer.msg(data.message);
                        getData();
                    }else{
                        layer.msg(data.message);
                    }

                }
            });
        }
    }


</script>
</body>
</html>
